﻿/**
 * 说明：类的继承、纯虚函数
 *
 */
#include <iostream>

using namespace std;
const static double PI = 3.14;
class Shape {
public:
    virtual double Area() = 0;
    virtual void Show() = 0;
    void Display() {
        cout << Area() << endl;
    }
};

class Circle :public Shape {
public:
    Circle();
    Circle(double r) :_r(r) {};
    virtual ~Circle() {};
    double Area() {
        return PI * _r * _r;
    }

    void Show() {
        cout << "circle" << endl;
    }
private:
    double _r;
};

class Triangle:public Shape{
public:
    Triangle();
    Triangle(double length, double height) :_length(length), _height(height) {};
    virtual ~Triangle() {};
    double Area() {
        return 0.5*_length*_height;
    }

    void Show() {
        cout << "triangle" << endl;
    }

private:
    double _length, _height;
};

int main()
{
    //std::cout << "Hello World!\n";
    Circle c(2);
    //c.Display();
    Triangle tri(1.1, 2.1);
    //tri.Display();

    Shape* shape[2];
    shape[0] = &c;
    shape[1] = &tri;
    for (int i = 0; i < 2; ++i) {
       /* cout << (shape[i]->Display()) << endl;*/
        shape[i]->Display();
    }




}

